Skip to content

FIX: resolve attribute cross-links in the class scope first - #706

Merged
larsoner merged 2 commits into
numpy:mainfrom
lazerg:fix-attribute-link-scope
Sep 11, 2026
Merged

FIX: resolve attribute cross-links in the class scope first#706
larsoner merged 2 commits into
numpy:mainfrom
lazerg:fix-attribute-link-scope

Conversation

@lazerg

@lazerg lazerg commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

On a class page numpydoc renders every entry of the Attributes list as :obj:`name <name>` . Sphinx resolves that
target against the current module before the current class, so an attribute whose name is also a module-level object
links to the wrong page. On the numpy.ufunc page the identity attribute links to the numpy.identity function
instead of numpy.ufunc.identity, and it has been doing that since at least numpy 1.20.

Prefixing the target with a dot makes the reference specific, so Sphinx tries the class scope first and falls back to
the module scope exactly as before when the attribute is not documented itself.

Reported in numpy/numpy#32532.

@larsoner

larsoner commented Sep 8, 2026

Copy link
Copy Markdown
Collaborator

Seems totally reasonable (and I had no idea about this "." behavior!). Would it be possible to add some test that fails on main but passes on this PR?

@lazerg

lazerg commented Sep 11, 2026

Copy link
Copy Markdown
Contributor Author

I added test_attribute_link_is_class_scoped in numpydoc/tests/test_docscrape.py. It builds a class with an attribute and checks the rendered link uses the dot prefix. I ran it against main: it fails (link comes out as <identity>). I ran it against this branch: it passes. Commit 8e7513c.

@larsoner
larsoner merged commit d33e5fe into numpy:main Sep 11, 2026
26 of 27 checks passed
@larsoner

Copy link
Copy Markdown
Collaborator

Thanks @lazerg !

@stefanv stefanv added this to the 1.11.0 milestone Sep 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants